package com.fly.base;

/**
 *
 */
public class ServiceException extends RuntimeException {

    public enum Code {
        //
        MORE_THAN_ONE(401, "查询结果只应该有一个，却查询出多个！"),
        //
        SAVE_FAIL(402, "保存失败！"),
        //
        UPDATE_FAIL(403, "更新失败！"),
        //
        DELETE_FAIL(404, "删除失败！");

        private final int code;
        private final String message;

        public int getCode() {
            return code;
        }

        public String getMessage() {
            return message;
        }

        Code(int code, String message) {
            this.code = code;
            this.message = message;
        }
    }

    private Code code;

    public ServiceException(Code code) {
        super(code.message);
        this.code = code;
    }

    public ServiceException(String message, Code code) {
        super(message);
        this.code = code;
    }

    public Code getCode() {
        return code;
    }

    public void setCode(Code code) {
        this.code = code;
    }
}
